<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="index.html">
        用户名：<input type="text" class="uName" name="username">
        <br>
        密&emsp;码：<input type="password" class="psw" name="password">
        <br>
        <input type="checkbox" class="ck">记住我
        <button type="sumit">提交</button>
    </form>
    <script>
        let uName = document.querySelector('.uName');
        let ck = document.querySelector('.ck');
        let btn = document.querySelector('button');

        btn.onclick = function () {
            if (ck.checked == true) {
                window.localStorage.setItem('uName', uName.value);
                window.localStorage.setItem('ck', ck.checked);
                window.sessionStorage.setItem('uName', uName.value)
            } else {
                window.sessionStorage.setItem('uName', uName.value);
                window.localStorage.clear();
            }
            window.location.href = "index.html";
        }
        uName.value = localStorage.getItem('uName');
        ck.checked = localStorage.getItem('ck');



    </script>

</body>

</html>